#!/usr/bin/python

# USECASE 01
#
# Define and apply simpe viewpoints
#
# Applying a VP to a music21 Stream copies the stream
# and saves the result to the lyric field

import music21
import music21.corpus

# Import a chorale
sBach = music21.corpus.parseWork('bach/bwv7.7')

from viewpoints import *
from constructors import * 

# List predefined viewpoints and constructors
listViewpoints()    

# Demo applies the viewpoint to a small amount of data
#PitchVP().demo(sBach)
#DurationVP().demo(sBach)

# Define a melodic interval viewpoint
# Sequences are numbered such that '0' is now, '1' is the event before, etc.
# By default the feature is assigned to template[0], i.e. now
miVP = UserVP("mi","melodic interval",[PitchVP(),PitchVP()],lambda l: l[0]-l[1])
listViewpoints()
#miVP.apply(sBach).show()

#Define a duration ratio viewpoint
drVP = UserVP("dr","duration ratio",[DurationVP(),DurationVP()],lambda l: l[0]/l[1])
listViewpoints()
#drVP.apply(sBach).show()

# Create a linked MI/DR viewpoint
linkedMIDR = LinkedVP("mi-dr","linked(mi,dr)",miVP,drVP)
listViewpoints()
linkedMIDR.apply(sBach).show()
